import { modal } from 'vue-strap'
import extend from 'extend'
import { showMsg, getAddVote } from '../../../../vuex/action'
export default {
  name: 'vote-configure',
  components: {
    'vue-modal': modal
  },
  props: ['showConfigure', 'ac', 'title'],
  data() {
    return {
      inputVote: ''
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xGetAddVote: getAddVote
    }
  },
  methods: {
    submit() {
      let reg = /\d+/g
      var ac = extend(true, {}, this.ac)
      if (reg.test(this.inputVote) && this.inputVote !== '') {
        this.xGetAddVote({
          customerId: ac.customerId,
          votes: this.inputVote
        })
          .then(() => {
            this.showConfigure = false
            window.location.reload()
          })
          .catch((res) => {
            this.xShowMsg({
              type: 'danger',
              content: res.error_msg
            })
          })
      } else {
        return this.xShowMsg({
          type: 'danger',
          content: '请输入数字'
        })
      }
    }
  }
}